package com.pro.controller;

import com.pro.domain.Cinema;
import com.pro.domain.Details;
import com.pro.domain.Film;
import com.pro.mapper.FilmMapper;
import com.pro.service.DetailsService;
import com.pro.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class DetailsController {

    @Autowired
    private DetailsService detailsService;

    @Autowired
    private FilmService filmService;

    /**
     * Find cinemas which the film's gonna show in
     * @param filmId
     * @return
     */
    @GetMapping("/queryCinemaToFilm")
    public Map<String, Object> queryCinemaToFilm(Long filmId) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Cinema> cinemas = detailsService.queryCinemaToFilm(filmId);
        Film film = filmService.queryFilmByFilmId(filmId);
        map.put("cinema", cinemas);
        map.put("film", film);
        return map;
    }

    /**
     * A decorating method
     * @param filmId
     * @return
     */
    @GetMapping("/queryDetailsByFilmId") //摆设
    public List<Details> queryDetailsByFilmId(Long filmId) {
        return detailsService.queryDetailsByFilmId(filmId);
    }

    /**
     * Get specific details a film's gonna release
     * @param filmId
     * @param cinemaId
     * @return
     */
    @GetMapping("/queryFilmSpecificDetails")
    public List<Details> queryFilmSpecificDetails(Long filmId, Long cinemaId) {
        return detailsService.queryFilmSpecificDetails(filmId, cinemaId);
    }

}
